package com.xm2.demo.system.shop.dao;

import com.xm2.demo.model.Stores;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Create
 * @create 2018-12-13 11:47
 * @Description：
 */
@Repository
public interface StoresRepository extends JpaRepository<Stores,Integer> {

    @Modifying
    @Transactional
    @Query(value="delete from Stores s where s.id in (:ids) ")
    void deleteByIds(@Param("ids") List<Integer> ids);

    @Query(nativeQuery = true,value = "select * from stores as s where s.stores_name like :name% limit :startRow,:size")
    List<Stores> findStoresByStoresNamePage(@Param("name") String storesName,@Param("startRow")Integer startRow,@Param("size")Integer size);

    List<Stores> findStoresByStoresName(String storesName);

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value="update stores as s set s.center_id = 0 where s.center_id = :id")
    void updateCenterId(@Param("id")Integer id);

    @Query(nativeQuery = true,value = "select * from Stores where center_id = :id")
    List<Stores> findStoresByCenterId(@Param("id")Integer id);
}
